﻿package mortal.game.view.mainUI
{
    import Message.DB.Tables.*;
    import Message.Public.*;
    import com.mui.controls.*;
    import com.mui.core.*;
    import com.mui.utils.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.display.*;
    import mortal.common.global.*;
    import mortal.game.resource.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.scene3D.player.info.*;
    import mortal.game.utils.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.menu.*;
    import mortal.game.view.mainUI.avatar.*;
    import mortal.game.view.mainUI.roleAvatar.*;

    public class RobotAvatar extends EntityAvatar
    {
        protected var _mofaBar:BaseProgressBar;
        protected var _carrer:GBitmap;
        private var _tboss:TBoss;
        private var _tRobot:TRobot;

        public function RobotAvatar()
        {
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.addMana();
            this.addCarrer();
            return;
        }// end function

        override protected function addBg() : void
        {
            this.pushUIToDisposeVec(UIFactory.gBitmap(ImagesConst.AvatarEntityBg, 0, 0, this));
            return;
        }// end function

        protected function addCarrer() : void
        {
            this._carrer = UIFactory.gBitmap(null, -10, 12, this);
            return;
        }// end function

        override protected function addLevel() : void
        {
            var _loc_1:* = GlobalStyle.textFormatHui;
            _loc_1.size = 12;
            _loc_1.color = GlobalStyle.colorHuangUint;
            _level = UIFactory.gTextField("", 60, 28, 50, 20, this, _loc_1, false);
            return;
        }// end function

        protected function addMana() : void
        {
            this._mofaBar = UICompomentPool.getUICompoment(BaseProgressBar);
            this._mofaBar.createDisposedChildren();
            this._mofaBar.setProgress(ImagesConst.AvatarEntityMana, true, 3, 1, 86, 8);
            this._mofaBar.setBg(BitmapDataConst.AlphaBMD, true, 89, 8);
            this._mofaBar.setLabel(BaseProgressBar.ProgressBarTextOver, -55, -5);
            this._mofaBar.mouseChildren = false;
            this._mofaBar.mouseEnabled = true;
            this._mofaBar.x = 54;
            this._mofaBar.y = 20;
            addChild(this._mofaBar);
            return;
        }// end function

        override protected function addBuff() : void
        {
            _buffPanel = UICompomentPool.getUICompoment(BuffPanel);
            _buffPanel.createDisposedChildren();
            _buffPanel.x = 103;
            _buffPanel.y = 32;
            this.addChild(_buffPanel);
            return;
        }// end function

        override protected function addAvatar() : void
        {
            _avatar = UIFactory.gImageBitmap("", 3, -29, _bgSprite);
            return;
        }// end function

        override protected function addName() : void
        {
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.size = 12;
            _name = UIFactory.gTextField("", 60, -10, 100, 20, this, _loc_1, false);
            return;
        }// end function

        override protected function addLifeBar() : void
        {
            _shengmingBar = UICompomentPool.getUICompoment(BaseProgressBar);
            _shengmingBar.createDisposedChildren();
            _shengmingBar.setProgress(ImagesConst.AvatarEntityLife, false, 3, 1, 89, 8);
            _shengmingBar.setBg(BitmapDataConst.AlphaBMD, true, 89, 8);
            _shengmingBar.setLabel(BaseProgressBar.ProgressBarTextOver, -53, -5);
            _shengmingBar.x = 54;
            _shengmingBar.y = 11;
            this.addChild(_shengmingBar);
            return;
        }// end function

        public function updateMana(event:Event = null) : void
        {
            if (!_entityInfo)
            {
                return;
            }
            this._mofaBar.setValue(_entityInfo.entityInfo.mana, _entityInfo.entityInfo.maxMana);
            return;
        }// end function

        public function updateCarrer() : void
        {
            if (!_entityInfo)
            {
                return;
            }
            var _loc_1:* = this._tRobot.career;
            if (_loc_1)
            {
                this._carrer.bitmapData = GlobalClass.getBitmapData(GameDefConfig.instance.getECarrerSmallPic(_loc_1));
            }
            else
            {
                this._carrer.bitmapData = null;
            }
            return;
        }// end function

        override public function updateLevel(event:Event = null) : void
        {
            if (!_entityInfo)
            {
                return;
            }
            _level.text = "Lv. " + _entityInfo.entityInfo.level;
            return;
        }// end function

        override public function updateAvatar() : void
        {
            if (_entityInfo && this._tRobot)
            {
                _avatar.imgUrl = AvatarUtil.getPlayerAvatarUrl(this._tRobot.career, _entityInfo.entityInfo.sex, AvatarUtil.Mid);
            }
            return;
        }// end function

        override public function updateEntity(param1:EntityInfo) : void
        {
            this._tboss = BossConfig.instance.getInfoByCode(param1.entityInfo.code);
            if (this._tboss.type == EBossType._EBossTypePlayerRobot)
            {
                this._tRobot = RobotConfig.instance.getRobotByCode(this._tboss.code);
            }
            if (this._tboss.type == EBossType._EBossTypePetRobot)
            {
                this._tRobot = RobotConfig.instance.getRobotByPetCode(this._tboss.code);
            }
            super.updateEntity(param1);
            this.updateCarrer();
            this.updateMana();
            PlayerMenuRegister.UnRegister(_bgSprite);
            PlayerMenuRegister.Register(_bgSprite, param1, PlayerMenuConst.NearbyPlayerOpMenu);
            return;
        }// end function

        override protected function addEntityEvent() : void
        {
            super.addEntityEvent();
            if (_entityInfo)
            {
                _entityInfo.addEventListener(EntityInfoEventName.UpdateMana, this.updateMana);
            }
            return;
        }// end function

        override protected function removeEntityEvent(event:EntityInfoEvent = null) : void
        {
            super.removeEntityEvent();
            if (_entityInfo)
            {
                _entityInfo.removeEventListener(EntityInfoEventName.UpdateMana, this.updateMana);
            }
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._mofaBar.dispose(param1);
            this._mofaBar = null;
            this._carrer.dispose(param1);
            this._carrer = null;
            return;
        }// end function

    }
}
